//
//  ccPageViewController.m
//  CloudCat
//
//  Created by Xiaomin Cai on 4/7/12.
//  Copyright (c) 2012 Taobao. All rights reserved.
//

#import "ccPageViewController.h"

@implementation ccPageViewController
@synthesize page;

- (NSString*)nameForMenuPage:(TabPage)aPage {
    switch (aPage) {
        case TabPageHome:
            return @"首页";
        case TabPageMine:
            return @"我的";
        case TabPageSearch:
            return @"搜索";
        case TabPageSNS:
            return @"社区";
        case TabPageMore:
            return @"更多";
        default:
            return @"";
    }
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject

- (id)initWithMenu:(TabPage)aPage {
    if (self = [super init]) {
        self.page = aPage;
    }
    return self;
}

- (id)init {
    if (self = [super init]) {
        _page = TabPageNone;
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// TTViewController

- (void)setPage:(TabPage)aPage {
    _page = aPage;
    
    self.title = [self nameForMenuPage:aPage];
    
    UIImage* image = [UIImage imageNamed:@"tab.png"];
    self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:self.title image:image tag:0] autorelease];
    
//    self.navigationItem.rightBarButtonItem =
//    [[[UIBarButtonItem alloc] initWithTitle:@"Order" style:UIBarButtonItemStyleBordered
//                                     target:@"tt://order?waitress=Betty&ref=toolbar"
//                                     action:@selector(openURLFromButton:)] autorelease];
    
    if (_page == TabPageHome) {
        self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                           @"Apple",
                           [TTTableTextItem itemWithText:@"apple.com" URL:@"http://www.apple.com"],
                           @"Pearl",
                           [TTTableTextItem itemWithText:@"microsoft" URL:@"http://www.microsoft.com"],
                           nil];
    } else if (_page == TabPageMine) {
        self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                           @"My Apple",
                           [TTTableTextItem itemWithText:@"apple.com" URL:@"http://www.apple.com"],
                           @"My Pearl",
                           [TTTableTextItem itemWithText:@"microsoft" URL:@"http://www.microsoft.com"],
                           nil];
    } else if (_page == TabPageSearch) {
        self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                           @"Search Apple",
                           [TTTableTextItem itemWithText:@"apple.com" URL:@"http://www.apple.com"],
                           @"Search Pearl",
                           [TTTableTextItem itemWithText:@"microsoft" URL:@"http://www.microsoft.com"],
                           nil];
    } else if (_page == TabPageSNS) {
        self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                           @"Apple Forum",
                           [TTTableTextItem itemWithText:@"apple.com" URL:@"http://www.apple.com"],
                           @"Pearl Forum",
                           [TTTableTextItem itemWithText:@"microsoft" URL:@"http://www.microsoft.com"],
                           nil];
    } else if (_page == TabPageMore) {
        self.dataSource = [TTListDataSource dataSourceWithObjects:
                           [TTTableTextItem itemWithText:@"Call Us" URL:@"tel:13065738222"],
                           [TTTableTextItem itemWithText:@"Text Us" URL:@"sms:13065738222"],
                           [TTTableTextItem itemWithText:@"Website" URL:@"http://www.apple.com"],
                           nil];
    }
}
@end
